package cn.zdm.designpattern.chainpattern;

import lombok.extern.slf4j.Slf4j;

/**
 * copyright (C), 2020, 北京同创永益科技发展有限公司
 *
 * @author ZhaoDeman
 * @version 1.0.0
 * <author>                <time>                  <version>                   <description>
 * ZhaoDeman        2020/12/4 17:12                 1.0
 * @program designpattern
 * @description
 * @create 2020/12/4 17:12
 */
@Slf4j
public class DescriptionChain {
    private static AbstractLogger getLogger() {
        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
        AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);
        errorLogger.setNextLogger(fileLogger);
        fileLogger.setNextLogger(consoleLogger);
        return errorLogger;
    }

    public static void main(String[] args) {
        log.info("责任链模式....");
        log.info("1、有多个对象可以处理同一个请求，具体哪个对象处理该请求由运行时刻自动确定");
        log.info("2、在不明确接收者的情况下，向多个对象中的一个提交一个请求");
        log.info("3、可动态指定一组对象处理请求");
        AbstractLogger logger = getLogger();
        logger.logMessage(AbstractLogger.INFO, "Info.....");
        logger.logMessage(AbstractLogger.DEBUG, "debug....");
        logger.logMessage(AbstractLogger.ERROR, "error...");
    }
}
